﻿package asanteIT.test_asanteIT;

import java.util.Arrays;
import java.util.Hashtable;

public class IndiceInvertido {
    
    private static Hashtable<String,String> contenedor = new Hashtable<String,String>();
    private static String[] datos;
 
    public static void crearIndiceInvertido(String[] data) {
        datos = (String[])data.clone();
     
        for(Integer i=0; i < data.length; i++){
        	data[i] = data[i].replace("-", " "); 
        	data[i] = data[i].replace(",", " ");
        	data[i] = data[i].replace("'", " ");
        	String[] aux = data[i].split(" ");
    
          	for(int j=0; j < aux.length; j++){
                	if (!contenedor.containsKey(aux[j])){
             	   		String nuevo1 = i.toString();
             	   		contenedor.put(aux[j],nuevo1);
                       	} else {
                	      	 	 String valor =contenedor.get(aux[j]);
                       			String nuevo2 = i.toString();
                        		if (!valor.contains(nuevo2)){
                        			contenedor.remove(aux[j]);
                           			contenedor.put(aux[j],valor+","+nuevo2);
                        		}
                      
                    		 } 
           	 }
        }
    }
	
    public static String[] get(String clave_buscar){
    
		if (contenedor.containsKey(clave_buscar)){
			String valor = contenedor.get(clave_buscar);
	       		String[] arr = valor.split(",");
	       		String[] resultado = new String[arr.length]; 
	        
	       		for(int i=0; i < arr.length; i++){
	        		resultado[i] = "``"+ datos[Integer.parseInt(arr[i])] +"´´";
	        	}    
			return resultado;
			
		}else {	
			String[] a = new String[0];
			return  a;
			}
		 
	}
    
    
}

    
